package com.estore.model;

import java.util.*;

public class Product {
    private String id;       // 商品ID
    private String name;     // 商品名称
    private double price;    // 价格
    private int stock;       // 库存
    private Set<String> tags; // 标签

    public Product(String id, String name, double price, int stock) {
        this(id, name, price, stock, new HashSet<>());
    }

    public Product(String id, String name, double price, int stock, Set<String> tags) {
        this.id = id;
        this.name = name;
        this.price = price;
        this.stock = stock;
        this.tags = tags;
    }

    // Getters and Setters...
    public String getId() { return id; }
    public void setId(String id) { this.id = id; }
    public String getName() { return name; }
    public void setName(String name) { this.name = name; }
    public double getPrice() { return price; }
    public void setPrice(double price) { this.price = price; }
    public int getStock() { return stock; }
    public void setStock(int stock) { this.stock = stock; }

    // Getter and Setter for tags
    public Set<String> getTags() { return Collections.unmodifiableSet(tags); }
    public void setTags(Set<String> tags) { this.tags = new HashSet<>(tags); }

    @Override
    public String toString() {
        return String.format("ID: %-5s | Name: %-20s | Price: $%-8.2f | Stock: %d | Tags: %s", id, name, price, stock, tags);
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof Product)) return false;
        Product product = (Product) o;
        return Objects.equals(id, product.id);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id);
    }
}